package com.lvyq.qrobot.util;

/**
 * @author lvyq
 * @version 1.0
 * Create by 2024-06-05 11:04
 */
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

public class GifDownloader {
    public static void downloadGif(String imageUrl, String destinationFile) {
        try (InputStream in = new URL(imageUrl).openStream();
             FileOutputStream out = new FileOutputStream(destinationFile)) {

            byte[] buffer = new byte[4096];
            int n;
            while ((n = in.read(buffer)) != -1) {
                out.write(buffer, 0, n);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        for (int i =0 ;i<300;i++){
            try {
                String imageUrl = "http://game.qqhome.cn/cyhcimg/achi/"+i+".gif"; // 网络GIF图片的URL
                String destinationFile = "E:\\qbot-wav\\img\\achi\\"+i+".gif";
                downloadGif(imageUrl, destinationFile);
            }catch (Exception e){
                continue;
            }

        }

    }
}